<?php
	// Interface function	
	function oh_module_page($tokens) {
		global $oh_object_page;
		if (count($tokens)>0) {
			if (($tokens[0] == "token")&&(count($tokens)>1)) {
				$page = isset($_GET['page']) ? $_GET['page'] : "home";
				$page_tokens = oh_tokens($page);
				return $page_tokens[$tokens[1]];
			}
			if (($tokens[0] == "is")&&(count($tokens)>1)) {
				$page = isset($_GET['page']) ? $_GET['page'] : "home";
				$page_tokens = oh_tokens($page);
				$temp = $tokens;
				foreach($temp as $i=>$t) {
					if ($t == "*") {
						$tokens[$i] = $page_tokens[$i-1];
					}
				}
				/*
				if (oh_tokens_last($tokens) == "*") {
					if (isset($page_tokens[count($tokens)-2])) {
						$tokens[count($tokens)-1] = $page_tokens[count($tokens)-2];					
					}
				} 
				*/
				$a = oh_tokens_implode_slice($tokens,1);
				$b = oh_tokens_implode($page_tokens);
				return ($a == $b);				
			}
			$stok = implode(".",$tokens);
			if (isset($oh_object_page->page[$stok])) {
				$xxx = $oh_object_page->page[$stok];
				if (false) {
				} else if ($stok == "width") {
					return ($oh_object_page->get_width());
				} else if ($stok == "header.menu") {
					return ($oh_object_page->get_header_menu());
				} else {
					if (oh_is_valid_function($xxx)&&(strlen($xxx)>3)) {
						return $xxx();
					} else {
						return $xxx;
					}
				}
			}			
			return "";
		}
		return $oh_object_page;
	} 
	require_once(dirname(__FILE__)."/the_page.php");

	// Main class of module
	class oh_class_page extends the_page {
		public $page;
		public $opos;
		public $func;
		function oh_class_page() {
			$this->func = array(
			    "content.body" => "oh_page_content",
   			    "sidebar" => "oh_page_sidebar",
			);
			$this->page = array(
				"width" => "auto",
				"header.menu" => array(
					"Dashboard" => ""
				),
			);
			oh("p")->add_rules("
				page = .(string);
			   .page = .(string);
			");
		}
		function set($i,$c) {
			global $oh_object_page;
			$this->page[$i] = $c;
			return $oh_object_page;
		}
		function load($i,$c) {
			global $oh_object_page;
			$this->page[$i] = $c;
			return $oh_object_page;
		}
		function open($i) {
			global $oh_object_page;
			$this->opos = $i;
			ob_start();
			return $oh_object_page;
		}
		function stop($i) {
			global $oh_object_page;			
			$o = ob_get_clean();		
			$this->page[$i] = $o;
			return $oh_object_page;
		}
		function have($i) {
			if (isset($this->page[$i])&&(strlen($this->page[$i])>0)) {
				return true;
			} else {
				return false;
			}
		}
		function show() {
			foreach($this->func as $key=>$func) {
				if (!$this->have($key)) {
					$this->open($key);
						if (function_exists($func)) {
		                    $func();					
						}					
					$this->stop($key);		
				}		
			}
			include(oh("path.framework.modules.page.themes.default")."/page.php");
		}
	}	
	// Main object of module
	global $oh_object_page;
	$oh_object_page = new oh_class_page();
?>
